SG Window
Callback Interfaces

©1998 by Stinga

Overview      Reference     How To...     FAQ

An interface is a collection of prototypes representing methods and properties the interface encapsulates; that is, it contains only the declarations for the member procedures. By using Implements statement in a Visual Basic class or form module you declare that module will provide its own version of interface implementation.

SG Window library defines two interfaces: IsgMessageSink and IsgPaintSink. If you implement these interfaces in a VB module and attach this implementation to the SG Window object, interface methods are called from the Window object. That's why we call them callback interfaces.

IsgMessageSink

IsgMessageSink interface contains only one method: Message. This method is called when there is a new enabled message in the window's message queue. For an example of how to use this interface look at Handling Messages topic.

IsgPaintSink

IsgPaintSink is interface specialized for window drawing. It's methods are called when window's client or frame should be painted.

Following example shows how to use IsgPaintSink for drawing on the windows client area:

' Declare interface
Implements IsgPaintSink

' SGWindow object
Private mWnd As SGWindow.Window

Private Sub Class_Initialize()
   ' Initialize SGWindow object
   Set mWnd = New SGWindow.Window
   mWnd.Hooked = True
   mWnd.SetPaintCallback Me
End Sub

Private Function IsgPaintSink_GetFlags() As sgWindow.PaintFlag
   ' Draw client area, and use default frame painting
   IsgPaintSink_GetFlags = pfClientPaint
End Function

Private Sub IsgPaintSink_FramePaint(ByVal hdc As Long)
   ' Use default frame painting
End Sub

Private Sub IsgPaintSink_ClientPaint(ByVal hdc As Long, ByVal left As Long, ByVal top As Long, ByVal right As Long, ByVal bottom As Long)
   ' Draw rectangle over whole client area
   Dim rc As RECT
   GetClientRect mWnd.HWND, rc
   Rectangle hdc, 0, 0, rc.right, rc.bottom
End Sub

Remarks

Main reason why you would want to use callbacks is their speed: callbacks are much faster then standard event mechanism.

For more info about interfaces and Implements keyword, please consult your VB online help and Books Online. Search for the keyword implements.